<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>User</title>
    	<link rel="stylesheet" type="text/css" href="./themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="./themes/icon.css">
	<script type="text/javascript" src="./jquery.min.js"></script>
	<script type="text/javascript" src="./jquery.easyui.min.js"></script>
</head>

<body>
	<div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'north'" style="height:50px">
        		<a href="#" id="addBtn" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加信息</a>
        		<a href="#" id="removesBtn" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除信息</a>
			<input class="easyui-searchbox" data-options="prompt:'Please Input Value',searcher:doSearch" style="width:100%">

        </div>
	<div data-options="region:'center',title:'Main Title',iconCls:'icon-ok'">
		
	</div>
	<script>
        $(document).ready(function(){
            $.ajax('http://localhost:3000/users/list',{
                type:'post'
            }).done(function(res){
                console.log(res);
            })
        });
        
        var cateId = null;
        $('#dg').datagrid({
		    url:'http://localhost:3000/users/list',
		    method:'post',
		    queryParams: {
				cateId: cateId
			},
		    fit:true,
		    pagination:true,
		    pageSize:10,
		    pageList:[10,20,30],
		    columns:[[
		        {field:'name',title:'姓名',width:100},
		        {field:'password',title:'密码',width:100},
					formatter: function(value,row,index){
						return "<a onclick=deleteData('"+ row._id+"')>删除</a> <a onclick=editData('"+ row._id+"')>修改</a>"
					}
		    ]]
		});
		
		
		function deleteData(id){
    			
    			$.messager.confirm('确认删除', '你确认删除数据吗？', function(r){
                if (r){
		    		$.ajax({
		    			type:"delete",
		    			url:"http://localhost:3000/users/data/" + id,
		    			async:true
		    		}).done(function(res){
		    			$("#dg").datagrid('reload');
		    		})
                }
            });
    	}
    		
    	function editData(id){
    			$.ajax({
    			type:"get",
    			url:"http://localhost:3000/users/data/" +id,
    			async:true
    		}).done(function(res){
    			$('#ff').form('load', res);
    			$('#dlg').dialog('open');
    		})
    	}
		
		
    </script>
</body>

</html>